package com.example.about_example.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {
    //数据存储在服务器的内存中
    private List<MessageInfo> messageInfos = new ArrayList<>();
    @RequestMapping("/publish")
    public boolean messagePublish(MessageInfo messageInfo) {
        //参数校验
        if (!StringUtils.hasLength(messageInfo.getFrom())
                || !StringUtils.hasLength(messageInfo.getTo())
                || !StringUtils.hasLength(messageInfo.getMessage())) {
            return false;
        }
        //添加留言
        messageInfos.add(messageInfo);
        return true;
    }
    @RequestMapping("/getMessage")
        public List<MessageInfo> getMessageInfo () {

            return messageInfos;
        }

}
